package Operation;

import java2021_9_23.Book;
import java2021_9_23.BookDao;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work() {
        System.out.println("新增书籍");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名:>");
        String name = scanner.next();
        System.out.println("请输入作者名字:>");
        String author = scanner.next();
        System.out.println("请输入价格(以分为单位):>");
        int price = scanner.nextInt();
        System.out.println("请输入类型:>");
        String type = scanner.next();
        Book book = new Book(name,author,price,type);
        //可以通过构造函数来传参,给book对象设置值,
        /*
         book.setName(bookName);
        book.setAuthor(author);
        book.setPrice(price);
        book.setType(type);
         */

        BookDao bookDao = new BookDao();
        boolean ret = bookDao.add(book);
        if(ret){
            System.out.println("新增书籍成功!");
        }else{
            System.out.println("新增书籍失败!");
        }

    }
}
